package com.usian.controller;

import com.usian.pojo.TbContent;
import com.usian.pojo.TbContentCategory;
import com.usian.service.ContentCategoryService;
import com.usian.utils.AdNode;
import com.usian.utils.PageResult;
import com.usian.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class ContentCategoryController {

    @Autowired
    private ContentCategoryService contentCategoryService;

    /**
     * @param id
     * @return
     */
    @RequestMapping("/selectContentCategoryByParentId")
    public List<TbContentCategory> selectContentCategoryByParentId(@RequestParam Long id){
        return contentCategoryService.selectContentCategoryByParentId(id);
    }

    @RequestMapping("/insertContentCategory")
    public Integer insertContentCategory(@RequestParam Integer parentId,@RequestParam String name){
        return contentCategoryService.insertContentCategory(parentId,name);
    }


    /**
     * @param categoryId
     * @return
     */
    @RequestMapping("/deleteContentCategoryById")
    public Integer deleteContentCategoryById(@RequestParam Long categoryId){
        return contentCategoryService.deleteContentCategoryById(categoryId);
    }

    /**
     * 内容分类管理修改
     * @param id
     * @param name
     * @return
     */
    @RequestMapping("updateContentCategory")
    public Integer updateContentCategory(@RequestParam Long id,@RequestParam String name){
        return contentCategoryService.updateContentCategory(id,name);
    }

    /**
     * @param categoryId
     * @return
     */
    @RequestMapping("/selectTbContentAllByCategoryId")
    public PageResult selectTbContentAllByCategoryId(@RequestParam(defaultValue = "1")Integer page, @RequestParam(defaultValue = "30")Integer rows,
                                                     @RequestParam  Long categoryId){
        return contentCategoryService.selectTbContentAllByCategoryId(page,rows,categoryId);
    }
    /*@RequestMapping("/selectTbContentAllByCategoryId")
    public List<TbContent> selectTbContentAllByCategoryId(@RequestParam Long categoryId){
        return contentCategoryService.selectTbContentAllByCategoryId(categoryId);
    }*/

    /**
     * @param tbContent
     * @return
     */
    @RequestMapping("/insertTbContent")
    public Integer insertTbContent(@RequestBody TbContent tbContent){
        return contentCategoryService.insertTbContent(tbContent);
    }

    /**
     * @param id
     * @return
     */
    @RequestMapping("/deleteContentByIds")
    public Integer deleteContentByIds(@RequestParam Long id){
        return contentCategoryService.deleteContentByIds(id);
    }

    /**
     * 查询首页大广告位
     * @return
     */
    @RequestMapping("/selectFrontendContentByAD")
    public List<AdNode> selectFrontendContentByAD(){
        return contentCategoryService.selectFrontendContentByAD();
    }

}
